<template>
	<view class="container" style="padding-top: 20px;padding-left: 50rpx;padding-right: 50rpx;">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="dataform.telephone" placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="dataform.password" placeholder="请输入密码" type="password" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				
					<button type="primary" @click="register">注册</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//定义页面数据 表单数据
				dataform: {
					telephone:"12345678912",
					password:"123456"
				},
				
			}
		},
		methods: {
            register(){
				//访问网络API,提交数据，获取数据，处理结果
				uni.request({
					url: 'http://localhost:8090/foodapp/user/register',
					method: 'POST',
					data: this.dataform,//请求参数
					success: res => {
						if (res.data.success) { //如果返回的数据的success属性为真
							uni.showToast({
								title: '注册成功',
								icon:'none'
							});
							uni.navigateTo({
								url:"/pages/my/login/login"
							})
						} else{
							uni.showToast({
								title: '注册失败',
								icon:'none'
							});
						}
						
					},
					fail: () => {
						uni.showToast({
							title: '网络错误',
							icon:'none'
						});
					},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
		background-image: url();
	background-position:top;
	}
</style>
